extends CanvasLayer

signal count_time_out
@onready var hp_bar = %hp_bar
@onready var exp_bar = %exp_bar
@onready var gold = $gold
@onready var timer = $Timer
@onready var time = $time
@onready var count = $count

var now_time:int = 0
var total_time:int = 30
var time_count:int = 1 # 第几波

var player

func update_info():
	hp_bar.max_value = player.total_hp
	hp_bar.value = player.cur_hp
	hp_bar.get_node("hp_value").text = str(player.cur_hp)+"/"+str(player.total_hp)
	exp_bar.max_value = player.max_exp
	exp_bar.value = player.cur_exp
	exp_bar.get_node("level").text = "LV."+str(player.level)
	gold.text = str(player.gold)
	
func timer_start():
	now_time = total_time
	timer.start()

func next_count():
	count_time_out.emit()
	time_count += 1
	count.text = "第%s波" % str(time_count)
	timer_start()
	pass

func _on_timeout():
	now_time -= 1
	if now_time <= 0:
		next_count()
		return
	time.text = str(now_time)
	timer.start()
	pass # Replace with function body.

# Called when the node enters the scene tree for the first time.
func _ready():
	player = get_tree().get_first_node_in_group("player")
	update_info()
	pass # Replace with function body.


func _on_player_player_info_update():
	update_info()
	pass # Replace with function body.
